package cn.francis.controller;

import cn.francis.service.SysModuleService;
import com.qfedu.agro.common.ResultInfo;
import com.qfedu.agro.pojo.SysModule;
import com.qfedu.agro.vo.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Name: SysModuleController
 * Package: cn.francis.controller
 * Date: 2024/10/26 - 11:30
 * Description:
 *
 * @author Junhui Zhang
 * @version v1.0
 */

@RestController
@RequestMapping("sys/module")
@CrossOrigin
@Slf4j
public class SysModuleController {

    @Autowired
    private SysModuleService moduleService;

    @GetMapping("/menu")
    @PreAuthorize("hasAuthority('系统管理')")
    public ResultInfo menu() {
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = loginUser.getSysUser().getId();
        List<SysModule> menuByUserId = moduleService.findMenuByUserId(id);

        return ResultInfo.success(menuByUserId);
    }
}
